<template>
  <iframe
    :src="iframeSrc"
    style="width: 100%; height: 100%"
    frameborder="0"
    @load="onIframeLoad"
    @error="onIframeError"
  ></iframe>
</template>

<script>
export default {
  data() {
    return {
      iframeSrc: "",
      error: "",
    };
  },
  mounted() {
    // 使用about:blank作为初始页面绕过部分限制
    this.iframeSrc = "about:blank";
  },
  methods: {
    onIframeLoad() {
      try {
        const iframe = document.querySelector("iframe");
        const reportUrl =
          "http://120.76.239.234:8000/ReportServer/Pages/ReportViewer.aspx?%2fCHProjectManagementReport%2fCH-项目管理工时报表&rs:Command=Render";

        // 尝试通过contentWindow修改location
        iframe.contentWindow.location.href = reportUrl;
      } catch (err) {
        this.error = "加载报表失败: " + err.message;
      }
    },
    onIframeError() {
      this.error = "无法加载报表，请在新标签页中打开";
    },
  },
};
</script>
